package com.example.utils;

public class MoneyCheck {

	public String toBig(String d) {
		String str = d;
		if (str.length() > 8) {
			return "金额巨大，已超出计数范围";
		}
		if (str.length() < 1) {
			return "";
		}
		StringBuffer sub = new StringBuffer();
		String str1[] = str.split("\\.");
		char[] strs = str1[0].toCharArray();
		char[] strs2 = {};
		if (str.contains("."))
			strs2 = str1[1].toCharArray();
		int j = strs.length + 1;
		for (int i = 0; i < strs.length; i++) {
			j--;
			if (i > 0) {
				if (strs[i - 1] == '0' && strs[i] == '0') {
					if (j == 5) {
						sub.append(this.getUnit(j));
					}
					continue;
				}
				if (strs[i - 1] == '0' && strs[i] != '0') {
					sub.append(this.getBig('0'));
					sub.append(this.getBig(strs[i]));
					sub.append(this.getUnit(j));
					continue;
				}

			}
			if (strs[i] == '0') {
				if (j == 5) {
					sub.append(this.getUnit(j));
				}
				continue;
			}
			sub.append(this.getBig(strs[i]));
			if (strs[i] == '0') {
				continue;
			}
			sub.append(this.getUnit(j));
		}
		if (str.contains(".")) {
			sub.append(this.getBig(strs2[0]) + "角");
			sub.append(this.getBig(strs2[1]) + "分");
		}
		String str2 = sub.toString();
		str2 = str2.replace("零角零分", "整");
		if (str2.endsWith("圆"))
			str2 = str2 + "整";
		if (Integer.valueOf(str) % 10 == 0)
			str2 = str2 + "圆整";
		return str2;
	}

	private String getBig(char a) {
		String s = "";
		switch (a) {
		case '1':
			s = "壹";
			break;
		case '2':
			s = "贰";
			break;
		case '3':
			s = "叁";
			break;
		case '4':
			s = "肆";
			break;
		case '5':
			s = "伍";
			break;
		case '6':
			s = "陆";
			break;
		case '7':
			s = "柒";
			break;
		case '8':
			s = "捌";
			break;
		case '9':
			s = "玖";
			break;
		case '0':
			s = "零";
			break;
		}
		return s;
	}

	private String getUnit(int i) {
		String s = "";
		switch (i) {
		case 1:
			s = "圆";
			break;
		case 2:
			s = "拾";
			break;
		case 3:
			s = "佰";
			break;
		case 4:
			s = "仟";
			break;
		case 5:
			s = "万";
			break;
		case 6:
			s = "拾";
			break;
		case 7:
			s = "佰";
			break;
		case 8:
			s = "仟";
			break;
		case 9:
			s = "亿";
			break;
		}
		return s;
	}

	public static void main(String[] args) {
		// TODO 自动生成方法存根
		MoneyCheck sb = new MoneyCheck();
		System.out.println(sb.toBig("1234567"));
	}
}
